package com.dragon.pear.pages.tab.main.mine;

import android.view.View;

import com.chris.dev.base.libs.v1.models.param.IdParam;
import com.chris.libs.base.x.mvpp.mvpp.DefaultPresenter;
import com.chris.libs.http.x.v1.CompleteCallback;
import com.chris.libs.http.x.v1.NetApi;
import com.chris.libs.http.x.v1.NetResponse;
import com.chris.libs.http.x.v1.NetResult;
import com.dragon.pear.api.DemoUserApi;
import com.dragon.pear.common.utils.DefaultHttp;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import okhttp3.RequestBody;

/**
 * @author Chris Chan
 * Create on： 2025-02-05 02:02
 * Use for: Mine 业务逻辑处理
 * Explain:
 */
public class MinePresenter extends DefaultPresenter<MineContract.UIView>
        implements MineContract.Presenter {
    // 数据中心
    private MineViewModel viewModel;

    // Dagger2注入构造方法
    @Inject
    public MinePresenter() {
    }

    // 传入数据中心
    public void setViewModel(MineViewModel viewModel) {
        this.viewModel = viewModel;
    }

    // 实例方法，一般由ViewProxy主动调用，必须在契约接口中定义
    @Override
    public void requestAndUpdate() {
        this.viewModel.setInfo("用户中心");
    }

    @Override
    public void getUserInfo() {
        String token = "Bearer thismyauthorizationtokenhahahahhahahaha";
        RequestBody body = NetApi.postRequestObjBody(token, IdParam.create(8888888));
        DefaultHttp.post(DemoUserApi.service.getUserInfo(token, body), new CompleteCallback<Map<String, Object>>() {
            @Override
            public void complete(NetResponse<NetResult<Map<String, Object>>> netResponse, boolean b, Map<String, Object> map) {
                String name = String.valueOf(map.get("name"));
                MinePresenter.this.viewModel.setUsername(name);
            }
        });
    }

    @Override
    public void getDataList(View ownView) {
        DefaultHttp.post(DemoUserApi.service.getDataList(IdParam.create("宫廷玉液酒")), (netResponse, b, list) -> {
            this.viewModel.setDataSize(list.size());
        });

        DefaultHttp.post(DemoUserApi.service.getDataList(IdParam.create("123")), new CompleteCallback<List<Map<String, Object>>>() {
            @Override
            public void complete(NetResponse<NetResult<List<Map<String, Object>>>> netResponse, boolean b, List<Map<String, Object>> maps) {

            }
        });
    }
}
